package cn.itcast.web;

import cn.itcast.pojo.ItemDoc;
import cn.itcast.pojo.RequestParams;
import cn.itcast.searchService.SearchService;
import com.hmall.common.dto.PageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class searchController {

    @Autowired
    SearchService service;

    @PostMapping("list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams param){
//        System.out.println("search被访问");
        return service.list(param);
    }

    @PostMapping("filters")
    public Map<String,List<String>> filters(@RequestBody RequestParams param){
//        System.out.println("过滤请求被访问");
        return service.filters(param);
    }

    @GetMapping("suggestion")
    public List<String> suggestion(String key){

//        System.out.println("自动补全"+key);
        return service.suggestion(key);
    }
}
